import React from 'react'
import {jiaAction, jianAction} from '../../redux/reducers/countReducer'
//导入两个 hook 函数
import {useSelector, useDispatch} from 'react-redux';

export default function ReactReduxCom() {
  //获取 redux 中的状态
  let count = useSelector(state => state.count); // use 使用 Selector 选择器
  //获得 dispatch 函数
  let dispatch = useDispatch();

  return (
    <div>
      <h2>当前的计数值为: {count}</h2>
      <button onClick={() => {
        dispatch(jiaAction(1));
      }}>新增</button>
      <button onClick={() => {
        dispatch(jianAction(1));
      }}>减少</button>
    </div>
  )
}
